<template>
    <div>
        <h1>当前求和为：{{sumResult}}</h1>
        <h3>当前求和更大为：{{moreBig}}</h3>
        <h3>我在{{$store.state.school}},学习{{subName}}</h3>
        <h3>列表中人数{{personList.length}};此处实现数据共享</h3>
         <select v-model.number="num">
            <option :value="1">1</option>
            <option :value="2">2</option>
            <option :value="3">3</option>
        </select>
        <button @click="add(num)">+</button>
        <button @click="dec">-</button>
        <button @click="addOdd">当前求和为奇数再加</button>
        <button @click="addWait">等一等再加</button>
    </div>
</template>

<script>
    import {mapState,mapGetters,mapMutations} from 'vuex'
     export default {
        name:'count',
        data() {
            return {
                num:1,
            }
        },
        methods: {
            add(){
                this.$store.commit('ADD',this.num)
            },
            dec(){
                this.$store.commit('DEC',this.num)
            },
            // ...mapMutations({add:'ADD',dec:'DEC'}),
            /**
             * **************************
             */
            addOdd(){
                this.$store.dispatch('addOdd',this.num)
            },
            addWait(){
                this.$store.dispatch('addWait',this.num)
            },
        },
        mounted() {
            // const x = mapState({sumResult:'sum',schoolName:'school',subName:'subject'});
            // console.log(x);
        },
        computed: {
            ...mapState({sumResult:'sum',schoolName:'school',subName:'subject',personList:'personList'}),
            ...mapGetters(['moreBig'])
        },
     }
</script>

<style scoped>
    button {
        margin-left: 10px;
    }
</style>